package com.focusai.efairy.ui.adapter.project;

import android.view.View;

import com.focusai.efairy.R;
import com.focusai.efairy.model.project.OnItemClickEditorListener;
import com.focusai.efairy.model.response.ProjectManageResponse;
import com.focusai.efairy.ui.adapter.base.BaseRecyclerAdapter;
import com.focusai.efairy.ui.adapter.base.BaseRecyclerViewHolder;

/**
 * Created by luo_guangwen on 2017/9/12.
 */

public class ProjectUserAdapter extends BaseRecyclerAdapter<ProjectManageResponse.UserItem> {

    private OnItemClickEditorListener<ProjectManageResponse.UserItem> listener;
    private boolean isCreateByOthers;

    public ProjectUserAdapter(boolean isCreateByOthers) {
        this.isCreateByOthers = isCreateByOthers;
    }

    @Override
    protected int getItemLayoutId() {
        return R.layout.item_manager_user_list;
    }

    @Override
    protected void onBindBaseRecyclerViewHolder(BaseRecyclerViewHolder holder, final int position) {
        final ProjectManageResponse.UserItem item = mList.get(position);
        holder.setText(R.id.text_lable, item.efairyuser_nickname);
        holder.setText(R.id.text_value, item.efairyuser_phonenumber);
        holder.setText(R.id.edit, "分配设备");
        if (this.isCreateByOthers){
            holder.getView(R.id.edit_manager_layout_line).setVisibility(View.GONE);
            holder.getView(R.id.edit_manager_layout_root).setVisibility(View.GONE);
        }else {
            holder.getView(R.id.edit_manager_layout_line).setVisibility(View.VISIBLE);
            holder.getView(R.id.edit_manager_layout_root).setVisibility(View.VISIBLE);
        }
        if (listener != null){
            holder.getView(R.id.llayout_edit).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.onEdit(item,position);
                }
            });
            holder.getView(R.id.llayout_delete).setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    listener.onDelete(item,position);
                }
            });
        }
    }

    public void setListener(OnItemClickEditorListener<ProjectManageResponse.UserItem> listener) {
        this.listener = listener;
    }
}
